package cn.cxl.utils;

import android.Manifest;
import android.app.Activity;
import android.content.pm.PackageManager;
import android.os.Build;

import androidx.core.app.ActivityCompat;
import androidx.core.content.ContextCompat;


/**
 * ====================================================
 * <p>
 * 作者：CXL
 * <p>
 * 创建时间：2022/7/27 10:07
 * ====================================================
 */
public class Permissions {
    public static void permissions(Activity activity)
    {
        if (Build.VERSION.SDK_INT >= 23)
        {

            if (ContextCompat.checkSelfPermission(activity,
                    Manifest.permission.READ_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED
                    || ContextCompat.checkSelfPermission(activity,
                    Manifest.permission.WRITE_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED

            )
            {

                ActivityCompat.requestPermissions(activity,
                        new String[] {Manifest.permission.READ_EXTERNAL_STORAGE, Manifest.permission.WRITE_EXTERNAL_STORAGE

                        },
                        1);
            }
            else
            {
                MyLog.e("Permissions", "1");
                //                Toast.makeText(this, "已开启权限", Toast.LENGTH_SHORT).show();
            }
        }
        else
        {
            MyLog.e("Permissions", "2");
        }

    }
}
